package com.entryLevel;

public class IntegerBreak0109_343 {
    public int integerBreak(int n) {
        if(n == 1 || n == 0) return 0;
        int[] dp = new int[n];  // dp[i]  i拆分，乘积最大dp[i]

        //初始化
        dp[0] = 0; // 0*0 = 0
        dp[1] = 0; //1*0 = 0
        dp[2] = 1;

        for (int i = 3; i <= n; i++) {
            for (int j = 0; j < i; j++) {
                int max = Math.max( j* dp[i-j], dp[i]);
                dp[i] = Math.max(max, j * (i - j));
            }
        }

        return dp[n-1];
    }
}
